package com.lizhi.yun.sync.rsz.handler;/**
 * @program: hbsf_yun
 * @name RszGametrainSyncHandler
 * @description: 游戏训练记录
 * @author: lizhi
 * @create: 2021-11-10 11:36
 */

import com.lizhi.common.yun.entity.RpcServicePOJO;
import com.lizhi.common.yun.enums.HeartBeartEnum;
import com.lizhi.utils.StringUtils;
import com.lizhi.utils.json.SamJsonUtil;
import com.lizhi.yun.db.rsz.dao.RszGameTrainDao;
import com.lizhi.yun.db.rsz.entity.RszGameTrainEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *@program: hbsf_yun
 *@name RszGametrainSyncHandler
 *@description: 游戏训练记录
 *@author: lizhi
 *@create: 2021-11-10 11:36
 */
@Slf4j
@Service
public class RszGameTrainSyncHandler {

    @Resource
    private RszGameTrainDao rszGameTrainDao;

    public String recv(String json){
        RpcServicePOJO rpcServicePOJO = new RpcServicePOJO();
        try {
            RszGameTrainEntity rszGameTrainEntity = SamJsonUtil.toObject(json, RszGameTrainEntity.class);
            log.info("康复磨砂卓游戏训练信息上传:{}", rszGameTrainEntity);
            RszGameTrainEntity gameTrainEntity = rszGameTrainDao.selectById(rszGameTrainEntity.gmTrId, rszGameTrainEntity.hospitalId, rszGameTrainEntity.hospitalSystemId);
            if (!StringUtils.isEmpty(gameTrainEntity)){
                rszGameTrainEntity.lid = gameTrainEntity.lid;
                rszGameTrainDao.updateByIdSelective(rszGameTrainEntity);
            } else {
                rszGameTrainEntity.lid = StringUtils.newId();
                rszGameTrainDao.insertRecord(rszGameTrainEntity);
            }
            rpcServicePOJO.setErrorCode(HeartBeartEnum.HEART_BEART_000000.getEnValue());
            rpcServicePOJO.setMessage(HeartBeartEnum.HEART_BEART_000000.getEnName());
        } catch (Exception e){
            e.printStackTrace();
        }
        return SamJsonUtil.toJson(rpcServicePOJO);
    }
}
